package org.yefei.homeworkday15.six;

public class Triangle extends Graphics {
	private double a, b, c;// 三条边长

	public Triangle(String type, double a, double b, double c) {
		super(type);
		this.a = a;
		this.b = b;
		this.c = c;
	}

	public double getA() {
		return a;
	}

	public void setA(double a) {
		if (a <= 0) {
			System.err.println("边长不能为非正数");
			a = 6;
		}
		this.a = a;
	}

	public double getB() {
		return b;
	}

	public void setB(double b) {
		if (b <= 0) {
			System.err.println("边长不能为非正数");
			b = 8;
		}
		this.b = b;
	}

	public double getC() {
		return c;
	}

	public void setC(double c) {
		if (c <= 0) {
			System.err.println("边长不能为非正数");
			c = 10;
		}
		this.c = c;
	}

	@Override
	// 周长
	public void calPerimeter() {
		double zc;
		if (a + b > c && a + c > b && b + c > a && a > 0 && b > 0 && c > 0) {
			zc = a + b + c;
			System.out.println(super.getType() + "的周长为" + zc);
		} else {
			System.out.println("不能构成三角形！");
		}
	}

	@Override
	// 面积
	public void calArea() {
		double p;
		if (a + b > c && a + c > b && b + c > a && a > 0 && b > 0 && c > 0) {
			p = (a + b + c) / 2;
			double sqrt = Math.sqrt(p * (p - a) * (p - b) * (p - c));
			System.out.println(super.getType() + "面积是：" + sqrt);
		} else {
			System.out.println("不能构成三角形！");
		}
	}

}
